package com.cuit.controller;

import com.cuit.params.SetPasswordParams;
import com.cuit.params.UserOption;
import com.cuit.params.UserParams;
import com.cuit.service.UserService;
import com.cuit.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author SYE
 * @date 2023/7/27 11:20
 * @desciption: 重置密码controller
 */
@RestController
@RequestMapping("/api")
@Api(value = "重置密码")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/adduser")
    @ApiOperation(value = "添加用户")
    public Result addUser(@RequestBody UserParams userParams){
        return userService.addUser(userParams);
    }

    @GetMapping("/deleteuser/{userId}")
    @ApiOperation(value = "删除用户")
    public Result deleteUser(@PathVariable("userId") String userId){
        return userService.deleteUser(userId);
    }

    @PostMapping("/resetpwd")
    @ApiOperation(value = "重置密码")
    public Result resetPwd(@RequestBody SetPasswordParams setPassword, @RequestHeader("Authorization") String token){
        return userService.resetPwd(setPassword,token);
    }

    @PostMapping("/reset/ezpasswd")
    @ApiOperation(value = "登录时检测到密码过于简单对密码进行更新")
    public Result resetEZPwd(@RequestBody SetPasswordParams setPasswordParams){
        return userService.resetEZPwd(setPasswordParams);
    }

    @GetMapping("/get/allUser/{page}/{pageSize}")
    @ApiOperation(value = "获取全部用户")
    public Result getAllUser(@PathVariable("page") Integer page,@PathVariable("pageSize") Integer pagesize){
        return userService.getAllUser(page,pagesize);
    }

    @PostMapping("/query/byOption/{page}/{pageSize}")
    @ApiOperation(value = "通过单位账号用户名称查询用户信息")
    public Result queryByOption(@RequestBody UserOption userOption,
                                @PathVariable("page") Integer page,
                                @PathVariable("pageSize") Integer pagesize){
        return userService.queryByOption(userOption,page,pagesize);
    }

    @PostMapping("/reset/userPwd")
    @ApiOperation(value = "修改其他用户的密码")
    public Result resetUserPwd(@RequestBody SetPasswordParams setPasswordParams){
        return userService.resetUserPwd(setPasswordParams);
    }

}
